package top.lshaci.learning;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * ArrayListTest
 *
 * <pre>
 *     泛型擦除
 * </pre>
 *
 * @author lshaci
 * @since 1.0.0
 */
public class ArrayListTest {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<String> list = new ArrayList<>();
        list.add("str");
//        list.add(123); // 编译报错
        Method add = ArrayList.class.getMethod("add", Object.class);
        add.invoke(list, 123);

        Object num = list.get(1);
        System.err.println(num); // 123
        System.err.println(list); // [str, 123]
        System.err.println(list.get(0).getClass()); // class java.lang.String
        System.err.println(((Object) list.get(1)).getClass()); // class java.lang.Integer

        w: for (int i = 0; i < 10; i++) {
            switch (i) {
                case 1:
                    System.err.println("1");
                    break w;
            }
            System.err.println(i);
        }
    }
}
